using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using GMAO.CORE;

namespace GMAO.CORE
{
    public sealed class DataProviderFactoy 
    {
  	    //Constructeur
	    //private DataProviderFactory() {}
        private static DataProvider _Instance;
        private static StringSQL _StringSQL;
 	    public static DataProvider GetInstance()
	    {
            if (_Instance == null)
                return GetInstance(ConfigurationSettings.AppSettings.Get("Provider"));
            else
                return _Instance;
	    }
        public static StringSQL GestStringSQL()
        {
            if (_StringSQL == null)
                return GestStringSQL(ConfigurationSettings.AppSettings.Get("Provider"));
            else
                return _StringSQL;
        }
 	    public static DataProvider GetInstance(string name)
	    {
	         switch (name.ToUpper())
		        {
		        case "OLEDB":
                    _Instance = new DataProviderOleDb();
		            break;
		        case "SQLSERVER":
                    _Instance = new DataProviderSqlClient();
		            break;
		        case "DEFAULT":
                    _Instance = new DataProviderSqlClient();
		            break;			
		        default:
                    _Instance = new DataProviderSqlClient();
		            break;
		        }
                return _Instance;
	    }
        public static StringSQL GestStringSQL(string name)
        {
            switch (name.ToUpper())
            {
                case "OLEDB":
                    _StringSQL = new StringOleBd();
                    break;
                case "SQLSERVER":
                    _StringSQL = new StringSQL_SERVER();
                    break;
                case "DEFAULT":
                    _StringSQL = new StringSQL_SERVER();
                    break;
                default:
                    _StringSQL = new StringSQL_SERVER();
                    break;
            }
            return _StringSQL;
        }
    }
}
